<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />

<title>Player Home Page</title>

<link rel="stylesheet" href="style.css" type="text/css" media="screen" />


<script type="text/javascript">

var xmlhttp

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function buy()
{
	var stockID=getCheckedValue(document.forms['stockRadioForm'].elements['stockID']);
	var share=document.getElementById("share").value;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="TransactionServlet";
	url=url+"?type=buy&stockid="+stockID+"&share="+share;
	//url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function sell()
{
	var stockID=getCheckedValue(document.forms['stockRadioForm'].elements['stockID']);
	var share=document.getElementById("share").value;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="TransactionServlet";
	url=url+"?type=sell&stockid="+stockID+"&share="+share;
	//url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}



function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("dynamicContent").innerHTML=xmlhttp.responseText;
	}
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	return null;
}

function getXMLObject()  //XML OBJECT
{
	var xmlHttp = false;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
		} catch (e2) {
			xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
		}
	}
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
		xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
	}

	return xmlHttp;  // Mandatory Statement returning the ajax object created
}

</script>

</head>

<body>

<div id="container">
	<!-- Start of Page Header -->

	<div id="header_container">
	<div id="page_header">




		<div id="header_welcome">
		<h3><BR><BR><BR>Welcome to Virtual Stock Game System</h3>

			<div id="welcome_text">

<p>This system is designed for <a href="http://bank.cs.columbia.edu/classes/cs4156/"> COMS W4156 Advanced Software Engineering </a> </p>
				

				

			</div>

		</div>

	</div>
	</div>

	<!-- End of Page Header -->

	<!-- Start of Left Sidebar -->

	<div id="left_sidebar">
	
		<!-- Start of User Login -->

		<div class="box_container">
		<div id="userlogin">

			<h2><span>User Login</span></h2>
			
			<c:set var="player" value="${sessionScope.playerDetails}"/>
			<form id="playerLogoutForm" action="PlayerLogoutServlet" method="post">

				<div class="form_field">
				<strong>Welcome, ${player.firstName} !</strong>
				</div>

				<div class="clearthis">&nbsp;</div>

				<div class="form_field">
				<input type="submit" id="logout" value="Logout" />
				</div>

			</form>
			
			<div id="link-password">
			<a href="playerHomePage.jsp"><strong>Back to player home page</strong></a>
			</div>

		</div>
		</div>

		<!-- End of User Login -->
		
				<!-- Start of Latest News -->

		<div class="box_container">
		<div id="news">

			<h2><span>Latest News</span></h2>
<h4>
Nov 09, 2009
</h4>

<p>If you're looking for New York Stock Exchange information, please click <a href="http://www.nyse.com/">NYSE</a>.</p>
				


<h4>
Nov 07, 2009
</h4>

<p>Even more websites all about Stock Exchange <a href="http://www.nyse.com/">NYSE</a>.</p>
<p>Even more websites all about Stock Exchange <a href="http://www.nyse.com/">NYSE</a>.</p>

			<div class="link-more">
			<a href="http://www.nyse.com/">Read More</a>
			</div>

			<div class="clearthis">&nbsp;</div>
		</div>
		</div>


		<!-- End of Latest News -->

	</div>

	<!-- End of Left Sidebar -->


	<!-- Start of Main Content Area -->

	<div id="maincontent_container">
	<div id="maincontent">


		<div id="maincontent_top">
			
			
			<!-- Start of How We Started -->
			<div id="started_container">
			<div id="registration">
			
				<!-- Start of List of Game Information -->
				
				<br>
				Game Information:
				<br>
				<c:set var="game" value="${requestScope.currentGame}"/>
				<table id="gamenformation" border="3">
				<tr>
					<th bgcolor=>Game ID</th>
					<th bgcolor=>Game Name</th>
				    <th bgcolor=>Creator ID</th>
					<th bgcolor=>Start Date</th>
					<th bgcolor=>Initial Balance</th>
					
				</tr>
				<tr>
				    
				    <td>${game.gameID}&nbsp;&nbsp;</td> 
				    <td>${game.gameName}&nbsp;&nbsp;</td> 
				    <td>${game.creator}&nbsp;&nbsp;</td> 
				    <td>${game.startDate}&nbsp;&nbsp;</td> 
				    <td>${game.initialBalance}&nbsp;&nbsp;</td> 
				</tr>
				</table>
				
				<!-- End of List of Game Information -->
				
				
				<div id="dynamicContent">
					<br><br><br><br>
					Portfolio
					<br><br>
					<c:set var="portfolio" value="${requestScope.portfolioDetails}"/>
					<table id="portfolioInformation" border="3">
					<tr >
					    <th bgcolor=>Portfolio ID</th>
					    <th bgcolor=>Game ID</th>
					    <th bgcolor=>Player ID</th>
					    <th bgcolor=>Balance</th>
					</tr>
					<tr>
					    <td>${portfolio.portfolioID}&nbsp;&nbsp;</td> 
					    <td>${portfolio.gameID}&nbsp;&nbsp;</td> 
					    <td>${portfolio.playerID}&nbsp;&nbsp;</td> 
					    <td>${portfolio.balance}&nbsp;&nbsp;</td>
					</tr> 
					</table>
					
					
					<br><br><br><br>
					All stocks in this portfolio
					<br><br>
					<table id="stocksInPortfolioTable" border="3">
					<tr >
					    <th bgcolor=>Stock ID</th>
					    <th bgcolor=>Stock Name</th>
					    <th bgcolor=>Current Price</th>
					    <th bgcolor=>Share</th>
					</tr>
					<c:forEach var="stock" begin="0" items="${requestScope.stockShareMap}">
					<tr>
					    <td>${stock.key.stockID}&nbsp;&nbsp;</td> 
					    <td>${stock.key.stockName}&nbsp;&nbsp;</td>
					    <td>${stock.key.currentPrice}&nbsp;&nbsp;</td>
					    <td>${stock.value}&nbsp;&nbsp;</td> 
					</tr> 
					</c:forEach>
					</table>
					
					<br><br><br><br>
					<h>The rank list of this game</h>
					<br><br>
					<table id="rankListTable" border="3">
					<tr >
					    <th bgcolor=>Player ID</th>
					    <th bgcolor=>First Name</th>
					    <th bgcolor=>Last Name</th>
					    <th bgcolor=>Portfolio Value</th>
					</tr>
					<c:forEach var="rank" begin="0" items="${requestScope.rankList}">
					<tr>
						<td>${rank.playerID}</td>
						<td>${rank.firstName}</td>
						<td>${rank.lastName}</td>
						<td>${rank.portfolioValue}</td>
					</tr>
					</c:forEach>
					</table>
				</div>
				
	
			</div>
			</div>

			<!-- End of How We Started -->


			<div id="right_container">
			
				<!-- Start of Make a Trade -->

				<div id="repairing">
				
				<br><br><br><br>
				All available stock in this game
				<br><br>
				
				<form name="stockRadioForm">
					<table id="stockListTable" border="3">
					<tr >
					    <th bgcolor=>select</th>
					    <th bgcolor=>Stock Name</th>
					    <th bgcolor=>Current Price</th>
					</tr>
					<c:forEach var="stock" begin="0" items="${requestScope.stockList}">
					<tr>
						<td><input type="radio" name="stockID" value="${stock.stockID}" /></td>
						<td>${stock.stockName}</td>
						<td>${stock.currentPrice}</td>
					</tr>
					</c:forEach>
					</table>
				</form>
				
				<div id="menu">
				<p>share</p>
				<input type="text" name="share" id="share" size="12" maxlength="8"/>
				</div>
				
				<div id="menu">
				<input type="button" onclick="javascript:buy();" value="Buy"/>
				</div>
				
				<div id="menu">
				<input type="button" onclick="javascript:sell();" value="Sell"/>
				</div>

				
				</div>

				<div class="clearthis">&nbsp;</div>

				<!-- End of Make a Trade -->
				

			</div>

			<div class="clearthis">&nbsp;</div>

		</div>


		<!-- Start of Featured Products -->

		<div id="featured_container">
		<div id="featured">
			
			

			<div class="clearthis">&nbsp;</div>
		</div>
		</div>

		<div class="clearthis">&nbsp;</div>

		<!-- End of Featured Products -->


	</div>
	</div>

	<!-- End of Main Content Area -->


<!-- Start of Page Footer -->

	<div id="page_footer">

	Powered by <a href="http://bank.cs.columbia.edu/classes/cs4156/">Lofty Number One Team</a>

	</div>

	<!-- End of Page Footer -->



	<div class="clearthis">&nbsp;</div>

</div>

</body>
</html>